define(['jquery', 'bootstrap', 'backend', 'table', 'form','vue'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/gold/index' + location.search,
                    add_url: 'order/gold/add',
                    // edit_url: 'order/gold/edit',
                    del_url: 'order/order/del',
                    multi_url: 'order/gold/multi',
                    import_url: 'order/gold/import',
                    table: 'order_other',
                }
            });

            var table = $("#table");
            Fast.config.openArea = ['60%','70%'];
            //在普通搜索渲染后
            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $("input[name='invite']", form).addClass("selectpage").data("source", "general/staff/index").data("primaryKey", "invite").data("field", "invite").data("orderBy", "id desc");
                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns:true,
                fixedRightNumber:1,
                fixedNumberWidth:200,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_sn', title: __('Order_sn'), operate: 'LIKE'},
                        {field: 'game', title: __('Game'), operate: 'LIKE'},
                        {field: 'cross', title: __('跨区'), searchList: $.getJSON("games/cross/crossList")},
                        {field: 'area', title: __('Area'), operate: 'LIKE'},
                        {field: 'server', title: __('Server'), operate: 'LIKE'},
                        {field: 'type_name', title: __('Type_name'), operate: 'LIKE'},
                        {field: 'deposit', title: __('有无赔付'),searchList: {"1":__('是'),"2":__('否')}, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'buy_type', title: __('出售方式'),searchList: {"1":__('平台代发'),"2":__('卖家发货')}, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'title', title: __('Title'), operate: 'LIKE',cellStyle: {css: {"max-width": "300px","white-space":"normal","word-wrap":"break-word","word-break":"keep-all"}}},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'num', title: __('Num')},
                        {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                        {field: 'fee', title: __('手续费'), operate:'BETWEEN'},
                        {field: 'true', title: __('卖家实际到账'), operate:'BETWEEN'},
                        {field: 'ontime', title: __('Ontime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,cellStyle: {css: {"max-width": "100px","white-space":"pre-line","word-wrap":"break-word","word-break":"break-all"}}},
                        {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,cellStyle: {css: {"max-width": "100px","white-space":"pre-line","word-wrap":"break-word","word-break":"break-all"}}},
                        {field: 'overtime', title: __('Overtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,cellStyle: {css: {"max-width": "100px","white-space":"pre-line","word-wrap":"break-word","word-break":"break-all"}}},
                        {field: 'payway', title: __('Payway'), operate: 'LIKE', operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'status', title: __('订单状态'),searchList: {"1":"待支付","2":"待发货","3":"已发货","4":"挂单","5":"已完成","7":"已撤单","9":"取消订单"}, formatter: Table.api.formatter.flag},
                        {field: 'complaint', title: __('是否投诉'),searchList: {"0":__('未投诉'),"1":__('已回复'),"2":__('待回复')}, formatter: Table.api.formatter.label},
                        {field: 'account', title: __('Account'), operate: 'LIKE'},
                        {field: 'personal.account', title: __('Personal.account'), operate: 'LIKE'},
                        {field: 'invite', title: __('Invite'), operate: 'LIKE'},
                        {field: 'admin.username', title: __('客服'), operate: 'LIKE'},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
//                                 {
//                                     name: 'detail',
//                                     text: __(''),
//                                     title: __('商品详情'),
//                                     classname: 'btn btn-xs btn-primary btn-dialog',
//                                     icon: 'fa fa-list',
//                                     url: 'goods/goods/edit?order_id={id}',

//                                 },
                                {
                                    name: 'manage',
                                    text: __(''),
                                    title: __('管控订单'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-retweet',
                                    url: 'order/gold/manage',

                                },
                                {
                                    name: 'chat',
                                    text: __(''),
                                    title: __('查看卖家聊天记录'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-bell-o',
                                    url: 'order/gold/chat',

                                },
                                {
                                    name: 'online',
                                    text: __(''),
                                    title: __('联系买/卖家'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-handshake-o',
                                    url: 'order/gold/online',

                                },
                                {
                                    name: 'info',
                                    text: __(''),
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-eye',
                                    url: 'order/gold/edit',

                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });
			//当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                //这里我们手动设置底部的值
                $("#stat1").text(data.extend.stat1);
                $("#stat2").text(data.extend.stat2);
                $("#stat3").text(data.extend.stat3);
                $("#stat4").text(data.extend.stat4);
                $("#stat5").text(data.extend.stat5);
                $("#cross1").text(data.cross[1].num);
                $("#cross2").text(data.cross[2].num);
                $("#cross3").text(data.cross[3].num);
                $("#cross4").text(data.cross[4].num);
                $("#cross5").text(data.cross[5].num);
                $("#cross6").text(data.cross[6].num);
                $("#cross7").text(data.cross[7].num);
                $("#cross8").text(data.cross[8].num);
                $("#cross9").text(data.cross[1].price);
                $("#cross10").text(data.cross[2].price);
                $("#cross11").text(data.cross[3].price);
                $("#cross12").text(data.cross[4].price);
                $("#cross13").text(data.cross[5].price);
                $("#cross14").text(data.cross[6].price);
                $("#cross15").text(data.cross[7].price);
                $("#cross16").text(data.cross[8].price);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        manage: function () {
            Controller.api.bindevent();
        },
        chat: function () {
            Controller.api.bindevent();
        },
        online: function () {
            Controller.api.bindevent();
        },
        info: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
                $('input[type=radio][name="row[status]"]').change(function(e) {
                    var status = $('input[name="row[status]"]:checked').val();
                    console.log(status);
                    if(status == 7){
                        $(".away").show();
                    }else{
                        $(".away").hide();
                    }

                })
                

            }
        }
    };
    return Controller;
});


